package br.ucb.musicbay.genero;

import java.util.Date;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Order;

public class GeneroDao implements GeneroInterfaceDao {

	private transient Session session;	
	
	public Session getSession() {
		return session;
	}

	public void setSession(Session session) {
		this.session = session;
	}

	@Override
	public boolean save(Genero genero) {
		try {
			this.session.save(genero);
			return true;
		} catch (Exception e) {
			throw new HibernateException("ERRO! ERRO - save(Artista artista) "+new Date());
		}	
	}

	@Override
	public boolean delete(Genero genero) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean update(Genero genero) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Genero select(Genero genero) {
		// TODO Auto-generated method stub
		return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Genero> recoverAll() {
		Criteria criteria = getSession().createCriteria(Genero.class).addOrder(Order.asc("genero"));		
		return criteria.list();
	}

	@Override
	public Genero recoverById(Integer id) {
		return (Genero)session.get(Genero.class, id);		
	}

}
